package com.kitty.game.pet.handler.upgrade;

import com.kitty.common.utils.SpringUtils;
import com.kitty.game.equip.message.RespNotifyMiscEx;
import com.kitty.game.pet.PetDataPool;
import com.kitty.game.pet.bean.PetObject;
import com.kitty.game.pet.model.Pet;
import com.kitty.game.role.model.Role;
import com.kitty.mina.message.MessagePusher;
import org.springframework.stereotype.Component;

/**宠物继承*/
@Component
public class PetExtendHandler extends UpgradePetHandler {


    @Override
    public String acceptUpgradePet(Role role, Pet pet, String ids, String itemPos, String costType, String otherPetPos) {
        logger.error("宠物顿悟{},物品id{},物品位置{},{},{}",pet.getName(),ids,itemPos,costType,otherPetPos);
        PetObject petObject = PetDataPool.getPetObject(pet.getName());
        Pet other = petService.getPetByPos(Byte.parseByte(otherPetPos), role);
        if (other == null) {
            MessagePusher.pushMessage(role,new RespNotifyMiscEx("宠物不存在"));
            return null;
        }
        if (role.getPetBox().getFightPetId() == pet.getId()){
            MessagePusher.pushMessage(role,new RespNotifyMiscEx("继承宠物不能参战状态"));
            return null;
        }
        if (role.getPetBox().getSupplyPetId() == pet.getId()){
            MessagePusher.pushMessage(role,new RespNotifyMiscEx("继承宠物不能掠阵状态"));
            return null;
        }
        if (role.getPetBox().getFightPetId() == other.getId()){
            MessagePusher.pushMessage(role,new RespNotifyMiscEx("继承宠物不能参战状态"));
            return null;
        }
        if (role.getPetBox().getSupplyPetId() == other.getId()){
            MessagePusher.pushMessage(role,new RespNotifyMiscEx("继承宠物不能掠阵状态"));
            return null;
        }
        if (pet.getFly() != other.getFly()){
            MessagePusher.pushMessage(role,new RespNotifyMiscEx("宠物没有飞升"));
            return null;
        }
        int level = pet.getLevel();
        int exp = pet.getExp();
        int wuxue = pet.getMartial();
        pet.setLevel(other.getLevel());
        pet.setExp(other.getExp());
        pet.setMartial(other.getMartial());
        other.setLevel((short) level);
        other.setExp(exp);
        other.setMartial(wuxue);
        role.save();
        SpringUtils.getPetService().loadPet(role,pet);
        SpringUtils.getPetService().loadPet(role,other);
        MessagePusher.pushMessage(role,new RespNotifyMiscEx("继承成功"));
        return null;
    }
}
